import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types'
//列表数据
export const columns: BasicColumn[] = [
  //  {
  //   title: '单据类型ID',
  //   align:"center",
  //   dataIndex: 'billTypeId'
  //  },
  {
    title: '单据类型',
    align: "center",
    sorter: true,
    dataIndex: 'billTypeName',
    width: 120
  },
  {
    title: '订单编号',
    align: "center",
    sorter: true,
    dataIndex: 'billCode',
    width: 120
  },
  //  {
  //   title: '交易币种ID',
  //   align:"center",
  //   dataIndex: 'currencyId'
  //  },
  {
    title: '交易币种',
    align: "center",
    dataIndex: 'currencyName',
    width: 100
  },
  {
    title: '日期',
    align: "center",
    sorter: true,
    dataIndex: 'billDate',
    width: 160
  },
  {
    title: '状态',
    align: "center",
    dataIndex: 'billStatus',
    width: 80,
    customRender: ({ text }) => {
      return render.renderDict(text, 'sale_order_bill_status');
    },
  },
  //  {
  //   title: '业务员ID',
  //   align:"center",
  //   dataIndex: 'salesmanId'
  //  },
  {
    title: '业务员',
    align: "center",
    width: 100,
    dataIndex: 'salesmanName'
  },
  //  {
  //   title: '客户ID',
  //   align:"center",
  //   dataIndex: 'customerId'
  //  },
  {
    title: '订货客户',
    align: "center",
    width: 200,
    dataIndex: 'customerName'
  },
  //  {
  //   title: '销售部门ID',
  //   align:"center",
  //   dataIndex: 'saleDepartId'
  //  },
  {
    title: '销售部门',
    align: "center",
    dataIndex: 'saleDepartName',
    width: 120
  },
  //  {
  //   title: '接单组织ID',
  //   align:"center",
  //   dataIndex: 'orderOrganizationId'
  //  },
  {
    title: '接单组织',
    align: "center",
    dataIndex: 'orderOrganizationName',
    width: 100
  },
  {
    title: '订单交期',
    align: "center",
    sorter: true,
    dataIndex: 'orderDeliveryDate',
    width: 120,
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
  },
  //  {
  //   title: '来源单据ID',
  //   align:"center",
  //   dataIndex: 'srcBillId'
  //  },
  //  {
  //   title: '税组合ID',
  //   align:"center",
  //   dataIndex: 'taxCombinationId'
  //  },
  //  {
  //   title: '税组合',
  //   align:"center",
  //   dataIndex: 'taxCombinationName'
  //  },
  {
    title: '贸易方式',
    align: "center",
    dataIndex: 'tradeMode',
    width: 120,
    customRender: ({ text }) => {
      return render.renderDict(text, 'sale_order_trade_mode');
    },
  },
  //  {
  //   title: '价格含税',
  //   align:"center",
  //   dataIndex: 'priceIncludesTax',
  //   customRender: ({ text }) => {
  //     return render.renderDict(text, 'sale_order_priceIncludes_tax');
  //   },
  //  },
  //  {
  //   title: '未税金额',
  //   align:"center",
  //   sorter: true,
  //   dataIndex: 'amountNotTaxed'
  //  },
  //  {
  //   title: '税额',
  //   align:"center",
  //   sorter: true,
  //   dataIndex: 'tax'
  //  },
  //  {
  //   title: '价税合计',
  //   align:"center",
  //   sorter: true,
  //   dataIndex: 'totalPriceTax'
  //  },
  //  {
  //   title: '付款条件ID',
  //   align:"center",
  //   dataIndex: 'paymentConditionId'
  //  },
  {
    title: '付款条件',
    align: "center",
    dataIndex: 'paymentConditionName',
    width: 120
  },
  //  {
  //   title: '立账条件ID',
  //   align:"center",
  //   dataIndex: 'accountConditionId'
  //  },
  {
    title: '立账条件',
    align: "center",
    dataIndex: 'accountConditionName',
    width: 120
  },
  //  {
  //   title: '出货原则ID',
  //   align:"center",
  //   dataIndex: 'shippingPrincipleId'
  //  },
  {
    title: '出货原则',
    align: "center",
    dataIndex: 'shippingPrincipleName',
    width: 120
  },
  {
    title: '备注',
    align: "center",
    dataIndex: 'remark',
    width: 180
  },
  {
    title: '第三方编码',
    align: "center",
    dataIndex: 'thirdPartyCode',
    ifShow: false,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "单据类型",
    field: "billTypeName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "订单编号",
    field: "billCode",
    component: 'Input',
    vagueSearch: true,
    colProps: { span: 6 },
  },
  {
    label: "日期",
    field: "billDate",
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    colProps: { span: 6 },

  },
  {
    label: "业务员",
    field: "salesmanName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "订货客户",
    field: "customerName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "销售部门",
    field: "saleDepartName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "订单交期",
    field: "orderDeliveryDate",
    component: 'DatePicker',
    componentProps: {
      getPopupContainer: () => document.body,
    },
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '单据类型ID',
    field: 'billTypeId',
    component: 'Input',
    show: false
  },
  {
    label: '单据类型',
    field: 'billTypeName',
    component: 'Input',
    slot: 'billTypeSlot',
    dynamicRules: () => {
      return [
        { required: true, message: '请选择单据类型!' },
      ];
    },
  },
  {
    label: '订单编号',
    field: 'billCode',
    component: 'Input',
    slot: 'billCodeSlot',
  },
  {
    label: '交易币种ID',
    field: 'currencyId',
    component: 'Input',
    show: false
  },
  {
    label: '交易币种',
    field: 'currencyName',
    component: 'Input',
    slot: 'currencySlot',
    dynamicRules: () => {
      return [
        { required: true, message: '请输入交易币种!' },
      ];
    },
  },
  {
    label: '日期',
    field: 'billDate',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: () => {
      return [
        { required: true, message: '请选择日期!' },
      ];
    },
    defaultValue: Date.now()
  },
  {
    label: '状态',
    field: 'billStatus',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "sale_order_bill_status",
      stringToNumber: true,
    },
  },
  // {
  //   label: '业务员ID',
  //   field: 'salesmanId',
  //   component: 'Input',
  //   show: false
  // },
  {
    label: '业务员',
    field: 'salesmanId',
    component: 'JSelectUserByDept',
    componentProps: {
      showButton: false,
      isRadioSelection: true,
      rowKey: 'id',
      labelKey: 'realname',
    },
  },
  {
    label: '客户ID',
    field: 'customerId',
    component: 'Input',
    show: false
  },
  {
    label: '客户编码',
    field: 'customerCode',
    component: 'Input',
    show: false
  },
  {
    label: '订货客户',
    field: 'customerName',
    component: 'Input',
    slot: 'customerSlot',
    // dynamicRules: () => {
    //   return [
    //     { required: true, message: '请选择订货客户!' },
    //   ];
    // },
  },
  // {
  //   label: '销售部门ID',
  //   field: 'saleDepartId',
  //   component: 'InputNumber',
  //   show: false
  // },
  {
    label: '销售部门',
    field: 'saleDepartId',
    component: 'JSelectDept',
    componentProps: ({ }) => {
      return {
        multiple: false,
        showButton: false,
        checkable: false,
        labelKey: 'departName'
      }
    },
  },
  {
    label: '接单组织ID',
    field: 'orderOrganizationId',
    component: 'InputNumber',
    show: false
  },
  {
    label: '接单组织',
    field: 'orderOrganizationName',
    component: 'Input',
    slot: 'organizationSlot',
    dynamicRules: () => {
      return [
        { required: true, message: '请选择接单组织!' },
      ];
    },
  },
  {
    label: "订单交期",
    field: "orderDeliveryDate",
    component: 'DatePicker',
    dynamicRules: () => {
      return [
        { required: true, message: '请选择订单交期!' },
      ];
    },
    componentProps: {
      getPopupContainer: () => document.body,
      valueFormat: 'YYYY-MM-DD'
    },
  },
  {
    label: '来源单据ID',
    field: 'srcBillId',
    component: 'InputNumber',
    show: false
  },
  {
    label: '贸易方式',
    field: 'tradeMode',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "sale_order_trade_mode",
      stringToNumber: true,
    },
  },
  {
    label: '付款条件ID',
    field: 'paymentConditionId',
    component: 'Input',
    show: false
  },
  {
    label: '付款条件',
    field: 'paymentConditionName',
    component: 'Input',
    slot: 'paymentConditionSlot',
  },
  {
    label: '立账条件ID',
    field: 'accountConditionId',
    component: 'Input',
    show: false
  },
  {
    label: '立账条件',
    field: 'accountConditionName',
    component: 'Input',
    slot: 'accountConditionSlot',
  },
  {
    label: '出货原则ID',
    field: 'shippingPrincipleId',
    component: 'Input',
    show: false
  },
  {
    label: '出货原则',
    field: 'shippingPrincipleName',
    component: 'Input',
    slot: 'shippingPrincipleSlot',
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input',
    ifShow: false
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
//子表单数据
//子表表格配置
export const busSaleOrderItemColumns: JVxeColumn[] = [
  {
    title: '行号',
    key: 'rowNum',
    type: JVxeTypes.inputNumber,
    width: "80px",
    placeholder: '请输入${title}',
    defaultValue: null,
    validateRules: [
      { required: true, message: '${title}不能为空' }
    ]
  },
  {
    title: '销售订单ID',
    key: 'saleOrderId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '料品ID',
    key: 'materialId',
    type: JVxeTypes.hidden,
  },
  {
    title: '料号',
    key: 'materialCode',
    type: JVxeTypes.slot,
    width: "160px",
    placeholder: '请输入${title}',
    defaultValue: '',
    slotName: 'action',
    validateRules: [
      {
        required: true,
        message: '请选择料号'
      }
    ]
  },
  {
    title: '料品',
    key: 'materialName',
    type: JVxeTypes.normal,
    width: "160px",
  },
  {
    title: '数量',
    key: 'orderQuantity',
    type: JVxeTypes.inputNumber,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [
      {
        required: true,
        message: '请输入数量'
      }
    ]
  },  
  {
    title: '是否OEM',
    key: 'oemNot',
    type: JVxeTypes.select,
    width: "140px",
    placeholder: '请选择${title}',
    validateRules: [
      {
        required: true,
        message: '是否OEM必填'
      }
    ],
    options: [{ value: 0, label: '否' }, { value: 1, label: '是' }],
    defaultValue: 0,
  },
  {
    title: 'BOM是否完整',
    key: 'bomComplete',
    type: JVxeTypes.select,
    width: "140px",
    placeholder: '请选择${title}',
    options: [{ value: 0, label: '否' }, { value: 1, label: '是' }],
    defaultValue: 0
  },
  // {
  //   title: '入库数量',
  //   key: 'storageQuantity',
  //   type: JVxeTypes.normal,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: ''
  // },
  // {
  //   title: '排产数量',
  //   key: 'productQuantity',
  //   type: JVxeTypes.normal,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: ''
  // },
  // {
  //   title: '关闭数量',
  //   key: 'closeQuantity',
  //   type: JVxeTypes.normal,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: ''
  // },
  // {
  //   title: '订单数量',
  //   key: 'orderQuantity',
  //   type: JVxeTypes.normal,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: ''
  // },
  {
    title: '订单交期',
    key: 'orderDeliveryDate',
    type: JVxeTypes.date,
    width: "140px",
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [
      {
        required: true,
        message: '请输入订单交期'
      }
    ]
  },
  {
    title: '生产组织ID',
    key: 'produceOrganizationId',
    type: JVxeTypes.hidden,
  },
  {
    title: '生产组织',
    key: 'produceOrganizationName',
    type: JVxeTypes.slot,
    width: "140px",
    placeholder: '请输入${title}',
    defaultValue: '',
    slotName: 'organizationSlot',
    validateRules: [
      {
        required: true,
        message: '请选择生产组织'
      }
    ]
  },
  {
    title: '已交数量',
    key: 'deliveryQuantity',
    type: JVxeTypes.normal,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: ''
  },
  {
    title: '单位ID',
    key: 'unitId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '单位',
    key: 'unitName',
    width: "80px",
    type: JVxeTypes.normal,
    disabled: true
  },
  {
    title: '备注',
    key: 'remark',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]


/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
